package com.coder.algorithm.leetcode

import kotlin.math.max

/**
 * [485. 最大连续 1 的个数](https://leetcode-cn.com/problems/max-consecutive-ones/)
 *
 * @author yuhus
 * @date: 2022/3/29
 */
object l_0485 {
    fun findMaxConsecutiveOnes(nums: IntArray): Int {
        var maxCount = 0
        var count = 0
        for (index in nums.indices) {
            if (nums[index] == 1) {
                count++
                if (count > maxCount) {
                    maxCount = count
                }
            } else {
                count = 0
            }
        }
        return maxCount
    }
}